import java.io.IOException;
import javax.swing.*;
import java.util.*;

public class BosikamUnPatai {
    public static void main(String[] args) throws IOException {
        String answer;
        /* JPanel panel = new JPanel();
        panel.add(new JRadioButton("Saskaitīšana"));
        panel.add(new JRadioButton("Atņemšana"));
        JOptionPane.showOptionDialog(null, panel, "Izvēle", 
        * JOptionPane.YES_NO_OPTION, 
        * JOptionPane.QUESTION_MESSAGE, null, null, null); */
        Random randomGenerator = new Random();
        int randomInt = randomGenerator.nextInt(2);
        int arguments1 = 0;
        int arguments2 = 0;
        int t = 0;
        if (randomInt == 0) {
            do {
            arguments1 = (int)(System.currentTimeMillis() % 30);
            arguments2 = (int)(System.currentTimeMillis() * 8 % 30);
            answer = JOptionPane.showInputDialog(null, "Cik ir " + arguments1
                + " + " + arguments2 + "? ", "Saskaitīšana", JOptionPane.QUESTION_MESSAGE);
            int atbilde = Integer.parseInt(answer);
            if (atbilde == (arguments1 + arguments2))
                JOptionPane.showMessageDialog(null, "Atbilde pareiza! \nIzklaidējies uz nebēdu.", "Bonbonga", JOptionPane.INFORMATION_MESSAGE);
            else {
                JOptionPane.showMessageDialog(null, "Atbilde NEpareiza!\nDators tiks izslēgts!", "Sēdies, divi!", JOptionPane.WARNING_MESSAGE);
                String shutdownCmd = "shutdown -P";
//                Process child = Runtime.getRuntime().exec(shutdownCmd);
            }
            t++;
            }while (t != 10);
        }
        else {
            do {
            arguments1 = (int)(System.currentTimeMillis() % 30);
            arguments2 = (int)(System.currentTimeMillis() * 8 % 30);
            answer = JOptionPane.showInputDialog(null, "Cik ir " + arguments1 
                + " - " + arguments2 + "? ", "Atņemšana", JOptionPane.QUESTION_MESSAGE);
            int atbilde = Integer.parseInt(answer);
            if (atbilde == (arguments1 - arguments2))
                JOptionPane.showMessageDialog(null, "Atbilde pareiza! \nIzklaidējies uz nebēdu.", "Bonbonga", JOptionPane.INFORMATION_MESSAGE);
            else {
                JOptionPane.showMessageDialog(null, "Atbilde NEpareiza!\nDators tiks izslēgts!", "Sēdies, divi!", JOptionPane.WARNING_MESSAGE);
                String shutdownCmd = "shutdown -P";
//                Process child = Runtime.getRuntime().exec(shutdownCmd);
            }
            t++;
            }while (t != 10);
        }
        
    }
}